//
//  NaviController.swift
//  MSwift
//
//  Created by 马龙波 on 2017/10/27.
//  Copyright © 2017年 马龙波. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa
import FDFullscreenPopGesture

class NaviController: UINavigationController {

    
    fileprivate let disposeBag = DisposeBag()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.fd_fullscreenPopGestureRecognizer.isEnabled = true
        
        let naviBar = UINavigationBar .appearance()
        
        naviBar.zs_setBackgroundColor(backgroundColor: UIColor.purple)
//        UINavigationBar .appearance() .setBackgroundImage(UIImage.init(named: "nabg"), for: .default)
//        naviBar.tintColor = UIColor.white
//        naviBar.barTintColor = UIColor.white

        UINavigationBar .appearance() .setBackgroundImage(UIImage.init(named: "navi_pic"), for: .default)
        
        naviBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor as NSAttributedStringKey : UIColor.white, NSAttributedStringKey.font as NSAttributedStringKey : UIFont.systemFont(ofSize: 17)]

    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.childViewControllers.count > 0 {
            let backBtn = UIButton()
            backBtn.theme_setImage(["MBack", "MBack"], forState: .normal)
            backBtn.sizeToFit()
            backBtn.rx
                .tap
                .subscribe(onNext: {
                    self.popViewController(animated: true)
                })
                .disposed(by: disposeBag)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backBtn)
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}
